package com.addplus.townmall.server.queue.config;

import com.addplus.townmall.server.api.modelenum.QueueEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class QueueConfig {



    @Bean(value = "orderExchange")
    public CustomExchange orderExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(QueueEnum.ORDER_QUEUE.getExchange(), "x-delayed-message", true, false, args);
    }

    @Bean(value = "orderQueue")
    public Queue orderQueue() {
        return new Queue(QueueEnum.ORDER_QUEUE.getQueue(), true);
    }

    @Bean(value = "bindingOrder")
    public Binding bindingOrder(Queue orderQueue, CustomExchange orderExchange) {
        return BindingBuilder.bind(orderQueue).to(orderExchange).with(QueueEnum.ORDER_QUEUE.getRoutingKey()).noargs();
    }

    @Bean(value = "msmExchange")
    public TopicExchange topicExchange() {
        return new TopicExchange(QueueEnum.MSM_QUEUW.getExchange(), true, false);
    }

    @Bean(value = "msmQueue")
    public Queue msmQueue() {
        return new Queue(QueueEnum.MSM_QUEUW.getQueue(), true);
    }

    @Bean(value = "bingdingMsm")
    public Binding bindingMsm(Queue msmQueue, TopicExchange msmExchange) {
        return BindingBuilder.bind(msmQueue).to(msmExchange).with(QueueEnum.MSM_QUEUW.getRoutingKey());
    }

    @Bean(value = "topicStockManagerExchange")
    public TopicExchange topicStockManagerExchange() {
        return new TopicExchange(QueueEnum.STOCK_MANAGER.getExchange(), true, false);
    }

    @Bean(value = "stockManagerQueue")
    public Queue stockManagerQueue() {
        return new Queue(QueueEnum.STOCK_MANAGER.getQueue(), true);
    }

    @Bean(value = "bingdingStockManager")
    public Binding bingdingStockManager(Queue stockManagerQueue, TopicExchange topicStockManagerExchange) {
        return BindingBuilder.bind(stockManagerQueue).to(topicStockManagerExchange).with(QueueEnum.STOCK_MANAGER.getRoutingKey());
    }

    @Bean(value = "topicStockFightManagerExchange")
    public TopicExchange topicStockFightManagerExchange() {
        return new TopicExchange(QueueEnum.FIGHT_STOCK_QUEUQ.getExchange(), true, false);
    }

    @Bean(value = "stockFightManagerQueue")
    public Queue stockFightManagerQueue() {
        return new Queue(QueueEnum.FIGHT_STOCK_QUEUQ.getQueue(), true);
    }

    @Bean(value = "bingdingStockFightManager")
    public Binding bingdingStockFightManager(Queue stockFightManagerQueue, TopicExchange topicStockFightManagerExchange) {
        return BindingBuilder.bind(stockFightManagerQueue).to(topicStockFightManagerExchange).with(QueueEnum.FIGHT_STOCK_QUEUQ.getRoutingKey());
    }


}
